home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 20
/
Cream of the Crop 20 (Terry Blount) (1996).iso
/
os2
/
bind493a.zip
/
named
/
named-xfer.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-12-06
|
39KB
|
1,634 lines
/*
* The original version of xfer by Kevin Dunlap.
* Completed and integrated with named by David Waitzman
* (dwaitzman@bbn.com) 3/14/88.
* Modified by M. Karels and O. Kure 10-88.
* Modified extensively since then by just about everybody.
*/
/*
* ++Copyright++ 1988, 1990
* -
* Copyright (c) 1988, 1990
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* -
* Portions Copyright (c) 1993 by Digital Equipment Corporation.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies, and that
* the name of Digital Equipment Corporation not be used in advertising or
* publicity pertaining to distribution of the document or software without
* specific, written prior permission.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
* CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
* -
* --Copyright--
*/
#if !defined(lint) && !defined(SABER)
char copyright[] =
"@(#) Copyright (c) 1988, 1990 The Regents of the University of California.\n\
portions Copyright (c) 1993 Digital Equipment Corporation\n\
All rights reserved.\n";
#endif /* not lint */
#if !defined(lint) && !defined(SABER)
static char sccsid[] = "@(#)named-xfer.c 4.18 (Berkeley) 3/7/91";
static char rcsid[] = "$Id: named-xfer.c,v 8.10 1995/12/06 20:34:38 vixie Exp $";
#endif /* not lint */
#include <sys/param.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <netinet/in.h>
#if defined(__osf__)
# include <sys/mbuf.h>
# include <net/route.h>
#endif
#if defined(_AIX)
# include <sys/time.h>
# define TIME_H_INCLUDED
#endif
#include <net/if.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <arpa/nameser.h>
#include <errno.h>
#include <resolv.h>
#include <stdio.h>
#include <syslog.h>
#if !defined(SVR4) || !defined(sun)
# include <math.h>
#endif
#include <ctype.h>
#include <signal.h>
#define MAIN_PROGRAM
#include "named.h"
#undef MAIN_PROGRAM
#ifndef LOG_PERROR
# define LOG_PERROR 0
#endif
static struct zoneinfo zone; /* zone information */
static char ddtfilename[] = _PATH_TMPXFER,
*ddtfile = ddtfilename,
*tmpname,
*domain; /* domain being xfered */
static int quiet = 0,
read_interrupted = 0,
curclass,
domain_len; /* strlen(domain) */
static FILE *fp = NULL,
*dbfp = NULL;
static char *ProgName;
static void usage __P((const char *));
static int getzone __P((struct zoneinfo *, u_int32_t, int)),
print_output __P((u_char *, int, u_char *)),
netread __P((int, char *, int, int));
static SIG_FN read_alarm __P(());
static const char *soa_zinfo __P((struct zoneinfo *, u_char *, u_char*));
extern char *optarg;
extern int optind, getopt();
void
main(argc, argv)
int argc;
char *argv[];
{
register struct zoneinfo *zp;
register struct hostent *hp;
char *dbfile = NULL, *tracefile = NULL, *tm = NULL;
int dbfd, ddtd, result, c, fd, closed = 0;
u_int32_t serial_no = 0;
u_int16_t port = htons(NAMESERVER_PORT);
struct stat statbuf;
#ifdef STUBS
int stub_only = 0;
#endif
#ifdef GEN_AXFR
int class = C_IN;
#endif
if (ProgName = strrchr(argv[0], '/'))
ProgName++;
else
ProgName = argv[0];
(void) umask(022);
/* this is a hack; closing everything in the parent is hard. */
for (fd = getdtablesize()-1; fd > STDERR_FILENO; fd--)
closed += (close(fd) == 0);
#ifdef RENICE
nice(-40); /* this is the recommended procedure to */
nice(20); /* reset the priority of the current process */
nice(0); /* to "normal" (== 0) - see nice(3) */
#endif
#ifdef LOG_DAEMON
openlog(ProgName, LOG_PID|LOG_CONS|LOG_PERROR, LOGFAC);
#else
openlog(ProgName, LOG_PID);
#endif
#ifdef STUBS
while ((c = getopt(argc, argv, "C:d:l:s:t:z:f:p:P:qS")) != EOF)
#else
while ((c = getopt(argc, argv, "C:d:l:s:t:z:f:p:P:q")) != EOF)
#endif
switch (c) {
#ifdef GEN_AXFR
case 'C':
class = get_class(optarg);
break;
#endif
case 'd':
#ifdef DEBUG
debug = atoi(optarg);
#endif
break;
case 'l':
ddtfile = (char *)malloc(strlen(optarg) +
sizeof(".XXXXXX") + 1);
if (!ddtfile)
panic(errno, "malloc(ddtfile)");
#ifdef SHORT_FNAMES
filenamecpy(ddtfile, optarg);
#else
(void) strcpy(ddtfile, optarg);
#endif /* SHORT_FNAMES */
(void) strcat(ddtfile, ".XXXXXX");
break;
case 's':
serial_no = strtoul(optarg, (char **)NULL, 10);
break;
case 't':
tracefile = optarg;
break;
case 'z': /* zone == domain */
domain = optarg;
domain_len = strlen(domain);
while ((domain_len > 0) &&
(domain[domain_len-1] == '.'))
domain[--domain_len] = '\0';
break;
case 'f':
dbfile = optarg;
tmpname = (char *)malloc((unsigned)strlen(optarg) +
sizeof(".XXXXXX") + 1);
if (!tmpname)
panic(errno, "malloc(tmpname)");
#ifdef SHORT_FNAMES
filenamecpy(tmpname, optarg);
#else
(void) strcpy(tmpname, optarg);
#endif /* SHORT_FNAMES */
break;
case 'p':
port = htons((u_int16_t)atoi(optarg));
break;
case 'P':
port = (u_int16_t)atoi(optarg);
break;
#ifdef STUBS
case 'S':
stub_only = 1;
break;
#endif
case 'q':
quiet++;
break;
case '?':
default:
usage("unrecognized argument");
/* NOTREACHED */
}
if (!domain || !dbfile || optind >= argc) {
if (!domain)
usage("no domain");
if (!dbfile)
usage("no dbfile");
if (optind >= argc)
usage("not enough arguments");
/* NOTREACHED */
}
if (stat(dbfile, &statbuf) != -1 &&
!S_ISREG(statbuf.st_mode) &&
!S_ISFIFO(statbuf.st_mode))
usage("dbfile must be a regular file or FIFO");
if (tracefile && (fp = fopen(tracefile, "w")) == NULL)
perror(tracefile);
(void) strcat(tmpname, ".XXXXXX");
/* tmpname is now something like "/etc/named/named.bu.db.XXXXXX" */
if ((dbfd = mkstemp(tmpname)) == -1) {
perror(tmpname);
if (!quiet)
syslog(LOG_ERR, "can't make tmpfile (%s): %m\n",
tmpname);
exit(XFER_FAIL);
}
#i